//
//  AnswerQuestionsViewController.m
//  SafeFoodManagerDemo
//
//  Created by ios-1 on 2018/3/7.
//  Copyright © 2018年 bob. All rights reserved.
//

#import "AnswerQuestionsViewController.h"
#import "SettingTableViewCell.h"
#import "AnswerTitleTableViewCell.h"
#import "AnswerContentTableViewCell.h"
#import "AnswerImageTableViewCell.h"
#import "QuestionDetailModel.h"
#import "UIImageView+LoadwebImage.h"
#import "AnswerViewController.h"
#import "ScoreViewController.h"
#import "StandardAnswerTableViewCell.h"
#import "AnswerModel.h"
#import "UITextView+Placeholder.h"
#import "ExaminationViewController.h"
@interface AnswerQuestionsViewController ()
@property(nonatomic,strong)TB_TableView *homeTableView;
@property(nonatomic,strong)UIView *tableFootview;
@property(nonatomic,strong)UIView *footView;
@property(nonatomic,strong)UIButton *confirmButton;
@property(nonatomic,strong)UIButton *nextButton;
@property(nonatomic,strong)QuestionDetailModel *questionDetailModel;
@property(nonatomic,strong)AnswerModel *answerModel;
@property(nonatomic,strong)AnswerViewController *answerview;
@property(nonatomic,strong)ScoreViewController *scoreview;
@property(nonatomic,assign)BOOL titleClick;  //是否显示标准答案
@end

@implementation AnswerQuestionsViewController
{
    int count_i;
    int count_j;
    CGFloat height1;
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"答题";
    count_i = 0;
    count_j = 0;
    self.titleClick = NO;
    
    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self.view addSubview:self.footView];
    [self.view addSubview:self.homeTableView];
    self.homeTableView.estimatedRowHeight= 200;
    
    [self loadDatas];
}

- (UIView*)footView
{
    if(_footView == nil)
    {
        _footView = [[UIView alloc]init];
        if (kDevice_Is_iPhoneX) {
            
            _footView.frame=CGRectMake(0, SCREEN_HEIGHT-45*SCREEN_WIDTH/320-64-34, SCREEN_WIDTH, 45*SCREEN_WIDTH/320);
        }else{
            _footView.frame=CGRectMake(0, SCREEN_HEIGHT-45*SCREEN_WIDTH/320-64, SCREEN_WIDTH, 45*SCREEN_WIDTH/320);
        }
        _footView.backgroundColor = [UIColor whiteColor];
        
        UIButton *confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        confirmBtn.backgroundColor = TBColorProvideBtnbg;
        confirmBtn.titleLabel.font = [UIFont systemFontOfSize:16];
        [confirmBtn setTitle:@"确定" forState:UIControlStateNormal];
        [confirmBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [confirmBtn addTarget:self action:@selector(confirmClick:) forControlEvents:UIControlEventTouchUpInside];
        [_footView addSubview:self.confirmButton = confirmBtn];
        
        UIButton *nextBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        nextBtn.backgroundColor = RGBCOLOR(255, 211, 52);
        nextBtn.titleLabel.font = [UIFont systemFontOfSize:16];
        [nextBtn setTitle:@"下一题" forState:UIControlStateNormal];
        [nextBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [nextBtn addTarget:self action:@selector(nextClick) forControlEvents:UIControlEventTouchUpInside];
        [_footView addSubview:self.nextButton = nextBtn];
        
    }
    return _footView;
}
- (void)refreshFootView
{
    //交卷后考生无法编辑 考官封卷后无法阅卷
    if([LoginStatuesModel getUserType] == 2)//考生
    {
        if(self.questionDetailModel.data.isAnswer == 1)//交卷
        {
            self.nextButton.frame = CGRectMake(0, 0, kScreenWidth, CGRectGetHeight(self.footView.frame));
        }else{//未交卷
            self.confirmButton.frame = CGRectMake(0, 0, kScreenWidth/2, CGRectGetHeight(self.footView.frame));
            self.nextButton.frame = CGRectMake(CGRectGetMaxX(self.confirmButton.frame), 0, kScreenWidth/2, CGRectGetHeight(self.footView.frame));
        }
    }else{//考官
        
        if(self.questionDetailModel.data.isMark == 1)//阅卷
        {
            self.nextButton.frame = CGRectMake(0, 0, kScreenWidth, CGRectGetHeight(self.footView.frame));
        }else{//未阅卷
            
            if(self.questionDetailModel.data.isAnswer==0)//考生还没交卷 考官不能编辑
            {
                self.nextButton.frame = CGRectMake(0, 0, kScreenWidth, CGRectGetHeight(self.footView.frame));
            }else{
                self.confirmButton.frame = CGRectMake(0, 0, kScreenWidth/2, CGRectGetHeight(self.footView.frame));
                self.nextButton.frame = CGRectMake(CGRectGetMaxX(self.confirmButton.frame), 0, kScreenWidth/2, CGRectGetHeight(self.footView.frame));
            }
        }
    }
    
}
- (void)confirmClick:(UIButton*)sender
{
    if([LoginStatuesModel getUserType] == 4)//老师阅卷
    {
        if(self.itemType == 1)//问答题考官要输入此题得分
        {
            [self MarkingHttp];
        }else{
            [self MarkingHttp];
        }
    }else{//考生作答
        if(self.itemType == 1)//问答题考生要输入答案
        {
            if(self.answerview.answerTextview.text.length <= 0)
            {
                [MBProgressHUD showWarnMessage:@"请输入你的答案"];
                return;
            }else{
                self.answerModel.examAnswer = self.answerview.answerTextview.text;
            }
            
            [self answerHttp];
        }else{
            NSArray *array = @[@"A",@"B",@"C",@"D",@"E",@"F",@"G",@"H",@"J"];
            NSMutableArray *answerArr = [NSMutableArray array];
            NSMutableArray *selectArr = [NSMutableArray array];
            
            for(int i=0;i<self.questionDetailModel.data.optionItems.count;i++)
            {
                QuestionDetailitem *detailitem = self.questionDetailModel.data.optionItems[i];
                if(detailitem.selected == 1)
                {
                    if(![selectArr containsObject:detailitem.name])
                    {
                        [selectArr addObject:detailitem.name];
                        [answerArr addObject:array[i]];
                    }
                }
            }
            
            if(answerArr.count){
                [self.answerModel.examOptions addObjectsFromArray:selectArr];
                [self answerHttp];
            }else{
                [MBProgressHUD showWarnMessage:@"请选择答案"];
            }
        }
    }
}

//下一题
- (void)nextClick
{
    //把所有分组数据整合在一个List里面
    if(!self.totalArray.count){
        for(int i=0;i<self.dataArray.count;i++)
        {
            QuestionsItemData *itemdata = self.dataArray[i];
            for(int j=0;j<itemdata.item.count;j++)
            {
                QuestionsItem *item= itemdata.item[j];
                [self.totalArray addObject:item];
            }
        }
    }
    
    //找到当前进入的是第几道题
    for(int j=count_j;j<self.totalArray.count;j++)
    {
        QuestionsItem *item=self.totalArray[j];
        if(item.paperItemId ==self.paperItemId.integerValue)
        {
            count_j = j;
            break;
        }
    }
    
    BOOL NEXTITEM = NO;
    QuestionsItem *nextitem = [QuestionsItem new];
    for(int j=count_j;j<self.totalArray.count;j++)
    {
        count_j = j;
        QuestionsItem *item=self.totalArray[j];
        if(item.paperItemId !=self.paperItemId.integerValue)
        {
            nextitem = item;
            NEXTITEM = YES;
            break;
        }
    }
    
    if(count_j != self.totalArray.count && NEXTITEM)
    {
        self.paperItemId = [NSString stringWithFormat:@"%zd",nextitem.paperItemId];
        self.itemType = nextitem.itemType;
        
        [self loadDatas];
    }else{
        [MBProgressHUD showTipMessageInWindow:@"已经是最后一题了"];
    }
}

- (UIView *)tableFootview
{
    if(!_tableFootview)
    {
        _tableFootview =[[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 300)];
        _tableFootview.backgroundColor = [UIColor whiteColor];
        
//        self.answerview = [AnswerViewController new];
//        self.scoreview = [ScoreViewController new];
        
//        if([LoginStatuesModel getUserType]==4)//考官
//        {
//            if(_itemType == 1)//问答题
//            {
//                CGFloat viewHeigh = 300;
//                self.answerview.view.frame = CGRectMake(0, 0, kScreenWidth, viewHeigh);
//
//                [self addChildViewController:self.answerview];
//                [_tableFootview addSubview:self.answerview.view];
//            }else{
//
//                CGFloat viewHeigh = 100;
//                self.scoreview.view.frame = CGRectMake(0, 0, kScreenWidth, viewHeigh);
//
//                [self addChildViewController:self.scoreview];
//                [_tableFootview addSubview:self.scoreview.view];
//            }
//        }else if([LoginStatuesModel getUserType]==1)//考生
//        {
//            CGFloat viewHeigh = 200;
//            if(_itemType == 1)
//            {
//                self.answerview.view.frame = CGRectMake(0, 0, kScreenWidth, viewHeigh);
//            }else{
//                self.answerview.view.frame = CGRectMake(0, 0, kScreenWidth, 0);
//            }
//            [self addChildViewController:self.answerview];
//            [_tableFootview addSubview:self.answerview.view];
//        }
        
        
//        CGFloat viewHeigh = [LoginStatuesModel getUserType]==4?300:200;
//        if([LoginStatuesModel getUserType]==4)
//        {
//            if(_itemType == 1)
//            {
//                self.answerview.view.frame = CGRectMake(0, 0, kScreenWidth, viewHeigh);
//            }else{
//                self.answerview.view.frame = CGRectMake(0, -200, kScreenWidth, viewHeigh);
//            }
//        }else{
//            if(_itemType == 1)
//            {
//                self.answerview.view.frame = CGRectMake(0, 0, kScreenWidth, viewHeigh);
//            }else{
//                self.answerview.view.frame = CGRectMake(0, 0, kScreenWidth, 0);
//            }
//        }
        
//        [_tableFootview addSubview:self.answerview.view];
    }
    
    return _tableFootview;
}

- (AnswerViewController*)answerview
{
    if(_answerview == nil)
    {
        _answerview = [AnswerViewController new];
    }
    return _answerview;
}
- (ScoreViewController*)scoreview
{
    if(_scoreview == nil)
    {
        _scoreview = [ScoreViewController new];
    }
    return _scoreview;
}
- (void)refreshTableFootview
{
    self.homeTableView.tableFooterView=self.tableFootview;
    
    //第一步：区分是考官还是考生
    //第二步：是问答题目还是非问答题目(单选题、多选题、判断题)
    //第三步：区分是封卷还是没封卷
    if([LoginStatuesModel getUserType]==4)//考官
    {
        if(self.questionDetailModel.data.itemType == 1)//问答题
        {
            CGFloat viewHeigh = 300;
            self.answerview.view.frame = CGRectMake(0, 0, kScreenWidth, viewHeigh);
            
            [self addChildViewController:self.answerview];
            [self.tableFootview addSubview:self.answerview.view];
        }else{
            
            CGFloat viewHeigh = 100;
            self.scoreview.view.frame = CGRectMake(0, 0, kScreenWidth, viewHeigh);
            
            [self addChildViewController:self.scoreview];
            [self.tableFootview addSubview:self.scoreview.view];
        }
    }else if([LoginStatuesModel getUserType]==2)//考生
    {
        if(self.questionDetailModel.data.itemType == 1)//问答题
        {
            CGFloat viewHeigh = 200;
            if(self.questionDetailModel.data.isMark == 1)//封卷
            {
                viewHeigh = 300;
            }
            
            self.answerview.view.frame = CGRectMake(0, 0, kScreenWidth, viewHeigh);
            [self addChildViewController:self.answerview];
            [self.tableFootview addSubview:self.answerview.view];
        }else{
            if(self.questionDetailModel.data.isMark == 1)//封卷
            {
                CGFloat viewHeigh = 100;
                self.scoreview.view.frame = CGRectMake(0, 0, kScreenWidth, viewHeigh);
                
                [self addChildViewController:self.scoreview];
                [self.tableFootview addSubview:self.scoreview.view];
            }else{
                self.answerview = [AnswerViewController new];
            }
        }
    }
    
    //考生相关
//    self.homeTableView.tableFooterView=self.tableFootview;
    
    if(self.questionDetailModel.data.examAnswer.length >0)
    {
        self.answerview.answerTextview.text =self.questionDetailModel.data.examAnswer;
    }
    
    if(self.questionDetailModel.data.examSuggest.length >0)
    {
        self.answerview.proposalTextview.text = self.questionDetailModel.data.examSuggest;
    }
    
    if(self.questionDetailModel.data.isAnswer == 1)
    {
        self.answerview.answerTextview.editable = NO;
        self.answerview.proposalTextview.editable = NO;
    }
    
    if(self.questionDetailModel.data.isMark == 1 || self.questionDetailModel.data.isAnswer != 1)
    {
        self.answerview.scoreTextView.editable = NO;
    }
    
    //考官相关
    self.scoreview.scoreTextView.text = [NSString stringWithFormat:@"%zd",self.questionDetailModel.data.examScore];
    if(self.questionDetailModel.data.examIsMark == 1)
    {
        self.answerview.scoreTextView.text = [NSString stringWithFormat:@"%zd",self.questionDetailModel.data.examScore];
    }else{
        self.answerview.scoreTextView.text = nil;
        self.answerview.scoreTextView.placeholder = @"请输入此题得分";
    }
    
    if(_itemType != 1 || self.questionDetailModel.data.isMark == 1)
    {
        self.scoreview.scoreTextView.text = [NSString stringWithFormat:@"%zd",self.questionDetailModel.data.examScore];
        self.scoreview.scoreTextView.editable = NO;
    }
    
    //分数区域是否隐藏
    BOOL hiden = ([LoginStatuesModel getUserType] != 4 && self.questionDetailModel.data.isMark != 1)?YES:NO;
    self.answerview.lineLab.hidden = hiden;
    self.answerview.scoreTitleLab.hidden = hiden;
    self.answerview.scoreTextView.hidden = hiden;
    
}
-(TB_TableView*)homeTableView
{
    if (!_homeTableView) {
        
        _homeTableView=[[TB_TableView alloc]initWithFrame:CGRectMake(10, 10, SCREEN_WIDTH-20, SCREEN_HEIGHT-64-60-10) style:UITableViewStylePlain];
        _homeTableView.backgroundColor = [UIColor whiteColor];
        _homeTableView.clipsToBounds = YES;
        _homeTableView.layer.cornerRadius =5;
        _homeTableView.separatorColor = [UIColor clearColor];
        _homeTableView.delegate=self;
        
        _homeTableView.dataSource=self;
        

        [_homeTableView registerNib:[UINib nibWithNibName:@"AnswerTitleTableViewCell" bundle:nil] forCellReuseIdentifier:@"AnswerTitleCell"];
        [_homeTableView registerNib:[UINib nibWithNibName:@"AnswerContentTableViewCell" bundle:nil] forCellReuseIdentifier:@"AnswerContentCell"];
        [_homeTableView registerNib:[UINib nibWithNibName:@"AnswerImageTableViewCell" bundle:nil] forCellReuseIdentifier:@"AnswerImageCell"];
        [_homeTableView registerNib:[UINib nibWithNibName:@"StandardAnswerTableViewCell" bundle:nil] forCellReuseIdentifier:@"StandardCell"];
    
    }
    
    return _homeTableView;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if(section == 0)
    {
        return self.titleClick?2:1;
    }else{
        if(self.itemType == 1)
        {
            return 1;
        }else
            return self.questionDetailModel.data.optionItems.count;
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.section == 1)
    {
        //非问答题 且没有交卷封卷时才可操作
        if(self.itemType !=1 && self.questionDetailModel.data.isAnswer !=1 && self.questionDetailModel.data.isMark !=1)
        {
            if(self.itemType !=3)//不是多选题
            {
                for(int i=0;i<self.questionDetailModel.data.optionItems.count;i++)
                {
                    QuestionDetailitem *detailitem = self.questionDetailModel.data.optionItems[i];
                    detailitem.selected = 0;
                }
            }
            QuestionDetailitem *detailitem = self.questionDetailModel.data.optionItems[indexPath.row];
            if(detailitem.selected == 0)
            {
                detailitem.selected = 1;
            }else{
                detailitem.selected = 0;
            }
            [self.homeTableView reloadData];
        }
    }
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    [_homeTableView registerNib:[UINib nibWithNibName:@"AnswerTitleTableViewCell" bundle:nil] forCellReuseIdentifier:@"AnswerTitleCell"];
    [_homeTableView registerNib:[UINib nibWithNibName:@"AnswerContentTableViewCell" bundle:nil] forCellReuseIdentifier:@"AnswerContentCell"];
    
    if(indexPath.section == 0)
    {
        if(indexPath.row == 0)
        {
            AnswerTitleTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"AnswerTitleCell" forIndexPath:indexPath];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            if(self.questionDetailModel.data != nil)
            {
                [cell refreshData:self.questionDetailModel];
            }
            
            cell.titleClickBlock = ^{
                self.titleClick = !self.titleClick;
                [self.homeTableView reloadData];
            };
            return cell;
        }else{
            StandardAnswerTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"StandardCell" forIndexPath:indexPath];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            if(self.questionDetailModel.data != nil)
            {
                [cell refreshData:self.questionDetailModel];
            }
            
            
            
            
            
            return cell;
        }
       
    }else{
        
        if(self.itemType == 1)
        {
            AnswerImageTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"AnswerImageCell" forIndexPath:indexPath];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;

            
           // cell.answerImage.contentMode = UIViewContentModeScaleAspectFit;
            
//            [cell.answerImage setImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@",ReqUrl,self.questionDetailModel.data.itemImg]]]]];
            
            [cell.answerImage LoadWebImageWithName:[NSString stringWithFormat:@"%@",self.questionDetailModel.data.itemImg] andIsOrgin:NO];
           
            
            
            UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(ShowHEAD)];
            cell.answerImage.userInteractionEnabled = YES;
//
            height1 = cell.answerImage.height;
            //cell.height = c;
            
           
            [cell.answerImage addGestureRecognizer:tap];
            
            return cell;
            
        }else{
            AnswerContentTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"AnswerContentCell" forIndexPath:indexPath];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            QuestionDetailitem *detailitem = self.questionDetailModel.data.optionItems[indexPath.row];
            [cell refreshData:detailitem];
            return cell;
        }
    }
    
    return nil;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(self.itemType == 1)
    {
        if(indexPath.section == 0)
        {
            return UITableViewAutomaticDimension;
        }else{
            
            return self.questionDetailModel.data.itemImg.length>0?400:0;
            //return UITableViewAutomaticDimension;
        }
    }else{
        return UITableViewAutomaticDimension;
    }
 
}

-(void)ShowHEAD
{
    [self.ScanPhotoArr removeAllObjects];
    self.ScanPhotoArr = [NSMutableArray array];
    [self.ScanPhotoArr addObject:[MWPhoto photoWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@",ReqUrl,self.questionDetailModel.data.itemImg]]]];
    
    [self GoToPhotoScanAndIndex:0];

}

#pragma mark *****************网络请求*********************
//获取答题信息
-(void)loadDatas
{
    [self showLoadingAnimation];
    NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
    [dictionary setObject:self.paperItemId forKey:@"paperItemId"];
    
    BaseReqApi *api=[[BaseReqApi alloc]initWithRequestUrl:@"/index.php/FoodCheckApi/paperItemDetail.json" andrequestTime:5 andParams:dictionary andRequestMethod:YTKRequestMethodPOST andCache:NO andCacheTime:0 andPostToken:YES];
    
    [api StarRequest:^(TBResponseStatus responseStatus, NSString *message, id responseObject) {
        [self stopLoadingAnimation];
        
        self.questionDetailModel = [QuestionDetailModel mj_objectWithKeyValues:responseObject];
        NSArray *array = @[@"A",@"B",@"C",@"D",@"E",@"F",@"G",@"H",@"J"];
        NSLog(@"%@",responseObject);
//        if (self.questionDetailModel.data.examAnswer.length > 0) {
//            NSInteger index = [array indexOfObject:self.questionDetailModel.data.examAnswer];
//            self.questionDetailModel.data.optionItems[index].selected = 1;
//        }
        
        if (responseStatus==1) {
            //请求成功
            if(self.questionDetailModel.data)
            {
                [self refreshTableFootview];
                [self.homeTableView reloadData];
                [self refreshFootView];
            }
            [self NetRequestSuccess:self scrollView:self.homeTableView];
            
        }else if (responseStatus==0||responseStatus==2)
        {
           
            [self NetRequestFail:self scrollView:self.homeTableView msg:message];
            
            self.Type=TBReqFalie;
            
        }else{
            //404需要重新登录了
            
            [UIAlertView bk_showAlertViewWithTitle:message message:nil cancelButtonTitle:@"取消" otherButtonTitles:@[@"确定"] handler:^(UIAlertView *alertView, NSInteger buttonIndex) {
                
                if (buttonIndex==1) {
                    
                    [self GotoLoginVC];
                }
                
            }];
        }
        
    }];
}

//考生提交答案
- (void)answerHttp
{
    [self showLoadingAnimation];
   
    NSString *postData = self.answerModel.mj_JSONString;
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setObject:self.paperItemId forKey:@"paperItemId"];
    [params setObject:postData forKey:@"postData"];
    
    BaseReqApi *api=[[BaseReqApi alloc]initWithRequestUrl:@"/index.php/FoodCheckApi/paperItemAnswer.json" andrequestTime:5 andParams:params andRequestMethod:YTKRequestMethodPOST andCache:NO andCacheTime:0 andPostToken:YES];
    
    [api StarRequest:^(TBResponseStatus responseStatus, NSString *message, id responseObject) {
        [self stopLoadingAnimation];
        
        if (responseStatus==1) {
            
            //注册答题的通知
            [[NSNotificationCenter defaultCenter] postNotificationName:@"answernote" object:nil];
            //请求成功
            [self nextClick];
            [self NetRequestSuccess:self scrollView:self.homeTableView];
        }else if (responseStatus==0||responseStatus==2)
        {
            [self NetRequestFail:self scrollView:self.homeTableView msg:message];

        }else{
            //404需要重新登录了
            
            [UIAlertView bk_showAlertViewWithTitle:message message:nil cancelButtonTitle:@"取消" otherButtonTitles:@[@"确定"] handler:^(UIAlertView *alertView, NSInteger buttonIndex) {
                
                if (buttonIndex==1) {
                    
                    [self GotoLoginVC];
                }
                
            }];
        }
        
    }];
}

//考官提交阅卷
- (void)MarkingHttp
{
    [self showLoadingAnimation];
    
    NSString *score = self.itemType == 1?self.answerview.scoreTextView.text:[NSString stringWithFormat:@"%zd",self.questionDetailModel.data.score];
    
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setObject:self.paperItemId forKey:@"paperItemId"];
    [params setObject:score forKey:@"examScore"];
    
    BaseReqApi *api=[[BaseReqApi alloc]initWithRequestUrl:@"/index.php/FoodCheckApi/paperItemMark.json" andrequestTime:5 andParams:params andRequestMethod:YTKRequestMethodPOST andCache:NO andCacheTime:0 andPostToken:YES];
    
    [api StarRequest:^(TBResponseStatus responseStatus, NSString *message, id responseObject) {
        [self stopLoadingAnimation];
        
        if (responseStatus==1) {
            
            //注册阅卷的通知
            [[NSNotificationCenter defaultCenter] postNotificationName:@"answernote" object:nil];
            
            //请求成功
            [self nextClick];
            [self NetRequestSuccess:self scrollView:self.homeTableView];
        }else if (responseStatus==0||responseStatus==2)
        {
            [self NetRequestFail:self scrollView:self.homeTableView msg:message];
            
        }else{
            //404需要重新登录了
            
            [UIAlertView bk_showAlertViewWithTitle:message message:nil cancelButtonTitle:@"取消" otherButtonTitles:@[@"确定"] handler:^(UIAlertView *alertView, NSInteger buttonIndex) {
                
                if (buttonIndex==1) {
                    
                    [self GotoLoginVC];
                }
                
            }];
        }
        
    }];
}
- (NSMutableArray *)totalArray
{
    if(!_totalArray)
    {
        _totalArray = [NSMutableArray array];
    }
    return _totalArray;
}
- (AnswerModel*)answerModel
{
    if(!_answerModel)
    {
        _answerModel = [AnswerModel new];
    }
    return _answerModel;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}



@end
